import {Component, Input, OnInit} from '@angular/core';
import {NzModalRef} from 'ng-zorro-antd/modal';
import {Clipboard} from '@angular/cdk/clipboard';
import {NzMessageService} from 'ng-zorro-antd/message';

@Component({
    selector: 'app-error-modal',
    templateUrl: './error-modal.component.html',
    styleUrls: ['./error-modal.component.less']
})
export class ErrorModalComponent implements OnInit {

    @Input()
    url: string;
    @Input()
    errorMessage: string;
    @Input()
    status: string;
    @Input()
    detail: string;
    @Input()
    code: string;

    constructor(private modal: NzModalRef, private clipboard: Clipboard, private message: NzMessageService) {
    }

    ngOnInit(): void {
    }

    close(): void {
        this.modal.destroy();
    }

    copy(): void {
        const result = this.clipboard.copy(`\n${this.url};\n${this.status};\n${this.errorMessage};\n${this.code};\n${this.detail}        `);
        if (result) {
            this.message.info('复制成功!');
        } else {
            this.message.error('复制失败!');
        }
    }
}
